<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>部门管理页面</title>
</head>
<body>
<div class="hrms_dept_container">
    <!-- 导航栏-->
    <%@ include file="./commom/head.jsp"%>


    <!-- 中间部分（左侧栏+表格内容） -->
    <div class="hrms_dept_body">
        <!-- 左侧栏 -->
        <%@ include file="./commom/leftsidebar.jsp"%>

        <!-- 部门表格内容 -->
        <div class="dept_info col-sm-10">
                    <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">账号修改</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal update_emp_form">
                    <div class="form-group">
                        <label  for="update_static_empName" class="col-sm-2 control-label">账号</label>
                        <div class="col-sm-8">
                            <input type="text" name="empCode" class="form-control" id="empCode" value="${emp.empCode }" disabled>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  for="update_static_empName" class="col-sm-2 control-label">姓名</label>
                        <div class="col-sm-8">
                            <p class="form-control-static" id="update_static_empName">${emp.empName}</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  for="update_static_empName" class="col-sm-2 control-label">旧密码</label>
                       <div class="col-sm-8">
                            <input type="password" name="empPassword" class="form-control" id="empPassword">
                            <span id="helpBlock_update_empPassword" class="help-block"></span>
                        </div>

                    </div>
                    <div class="form-group">
                        <label  for="update_static_empName" class="col-sm-2 control-label">新密码</label>
                      <div class="col-sm-8">
                            <input type="password" name="newPassword" class="form-control" id="newPassword">
                            <span id="helpBlock_update_newPassword" class="help-block"></span>
                        </div>
                    </div>
                     <div class="form-group">
                        <label  for="update_static_empName" class="col-sm-2 control-label">确认密码</label>
                      <div class="col-sm-8">
                            <input type="password" name="rnewPassword" class="form-control" id="rnewPassword">
                            <span id="helpBlock_update_rnewPassword" class="help-block"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="update_empEmail" class="col-sm-2 control-label">邮箱</label>
                        <div class="col-sm-8">
                            <input type="email" name="empEmail" class="form-control" id="update_empEmail" value="${emp.empEmail }">
                            <span id="helpBlock_update_inputEmail" class="help-block"></span>
                        </div>
                    </div>
                
                  
                    <div class="form-group">
                        <label for="update_department" class="col-sm-2 control-label">部门</label>
                        <div class="col-sm-8">
                            <div class="checkbox">
                                <select class="form-control" name="deptId" id="update_department">
                                    <option value="${emp.deptId }">${emp.empdeptName }</option>
                       
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary emp_update_btn" id="save" style="width:100px">保存</button>
            </div>
        </div><!-- /.modal-content -->
        </div><!-- /.dept_info -->
    </div><!-- /.hrms_dept_body -->


</div><!-- /.hrms_dept_container -->
<script type="text/javascript">
$(function(){
	//确认按钮
	$("#save").click(function(){
            $.ajax({
                url:"/HRMS/user/empmodify",
                type:"POST",
                data:{"empPassword":$("#rnewPassword").val(),"empEmail":$("#update_empEmail").val(),
                	"deptId":$("#update_department").val(),"empCode":$("#empCode").val()},
                success:function (result) {
                	console.log(result);
                    if (result.code == "true"){
                        alert("员工修改成功成功");
                        $('#emp-add-modal').modal("hide");
                        window.location.href="${pageContext.request.contextPath}/user/emmpage.html";
            
                        //跳往最后一页，由于新增记录，所以要重新查询总页数
                       
                    } else {
                        alert("员工新增失败！");
                    }
                }

            });
        })

        
	//ajax获取部门列表
	$(".modal-content").one("click",function(){
        $.ajax({
            url:"/HRMS/user/deptname",
            type:"GET",
            success:function (result) {
            	console.log(result);
                    $.each(result.list, function () {
                        var optEle = $("<option></option>").append(this.deptName).attr("value", this.deptId);
                        optEle.appendTo("#update_department");
                    });
            }

        });
	})
	//确认密码确认
	$("#rnewPassword").change(function(){
		var newp=$("#newPassword").val();
		var rnewp=$("#rnewPassword").val();
		if(rnewp==newp){
			  $("#rnewPassword").parent().parent().removeClass("has-error");
              $("#rnewPassword").parent().parent().addClass("has-success");
              $("#helpBlock_update_rnewPassword").text("确认密码正确！");

		}
		else{
            $("#rnewPassword").parent().parent().removeClass("has-sucess");
            $("#rnewPassword").parent().parent().addClass("has-error");
            $("#helpBlock_update_rnewPassword").text("两次密码不一致！");
		}
	})
	//新密码确认
	$("#newPassword").change(function(){
		var newp=$("#empPassword").val();
		var rnewp=$("#newPassword").val();
		if(rnewp==newp){//新密码和旧密码相同
			 $("#newPassword").parent().parent().removeClass("has-sucess");
	            $("#newPassword").parent().parent().addClass("has-error");
	            $("#helpBlock_update_newPassword").text("新密码不能与旧密码相同！");
		}
		else{
			 $("#newPassword").parent().parent().removeClass("has-error");
             $("#newPassword").parent().parent().addClass("has-success");
             $("#helpBlock_update_newPassword").text("新密码正确！");
		}
	})

	//旧密码判断
	  $("#empPassword").change(function () {
	        var empPassword = $("#empPassword").val();
	        var empCode = $("#empCode").val();
	        console.log(empCode);
	        $.ajax({
	            url:"/HRMS/user/dopassword",
	            type:"GET",
	            data:{"empPassword":empPassword,"empCode":empCode},
	            success:function (result) {
	            console.log(result);
	                if (result.code == "error"){
	                    $("#empPassword").parent().parent().removeClass("has-sucess");
	                    $("#empPassword").parent().parent().addClass("has-error");
	                    $("#helpBlock_update_empPassword").text("密码不正确！");
	                 
	                }else {
	                    $("#empPassword").parent().parent().removeClass("has-error");
	                    $("#empPassword").parent().parent().addClass("has-success");
	                    $("#helpBlock_update_empPassword").text("密码正确！");
	                }
	            }
	        });
	    });
	  //邮箱验证
	 $("#update_empEmail").change(function () {
		 
        var updateEmpId = $(this).attr("updateEmpId");
        //4 进行修改，对修改的邮箱格式进行判断；
        var regEmail = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
        var updateEmpEamil = $("#update_empEmail").val();
        if (!regEmail.test(updateEmpEamil)){
            $("#update_empEmail").parent().parent().removeClass("has-sucess");
            $("#update_empEmail").parent().parent().addClass("has-error");
            $("#helpBlock_update_inputEmail").text("邮箱格式不正确！");
            return false;
        }else {
            $("#update_empEmail").parent().parent().removeClass("has-error");
            $("#update_empEmail").parent().parent().addClass("has-success");
            $("#helpBlock_update_inputEmail").text("");
        }
	 })
	 
})
</script>
</body>
</html>
